
Texture2D SpriteSheetTexture;

float3 worldUp = float3(0,1.0f,0);

cbuffer cbPerObject
{
	float4x4 gWVP;
	float4x4 gWorld;
	float3 gEyePos;
	float4 gSunColor;
};

BlendState alphablend
{
	BlendEnable[0] = TRUE;
	SrcBlend = SRC_ALPHA;
	DestBlend = INV_SRC_ALPHA;
	BlendOp = ADD;
	SrcBlendAlpha = ZERO;
	DestBlendAlpha = ZERO;
	BlendOpAlpha = ADD;
	RenderTargetWriteMask[0] = 0x0F;
};

SamplerState samLinear
{
    Filter = MIN_MAG_MIP_LINEAR;
    AddressU = Wrap;// of Mirror of Clamp of Border
    AddressV = Wrap;// of Mirror of Clamp of Border
};

RasterizerState NoCull
{
	CullMode = NONE;
};
struct VertexShaderInput
{
    float3 Position : POSITION;
    float2 TexCoord : TEXCOORD;
	float4 Extras : NORMAL;
};

struct VertexShaderOutput
{
    float4 Position : SV_POSITION;
	float4 PosW		: TEXCOORD0;
    float2 TexCoord : TEXCOORD1;
};

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output;

	float3 sideVector;
	float3 upVector;	
	float4 finalPos = mul(float4(input.Position, 1.0f), gWVP);

	sideVector = normalize(cross(gEyePos,worldUp));			
	upVector = normalize(cross(sideVector,gEyePos));

    output.Position = finalPos;
	output.PosW = mul(float4(input.Position, 1.0f), gWorld);
    output.TexCoord = (input.TexCoord);

    return output;
}

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
	float3 col = SpriteSheetTexture.Sample( samLinear, input.TexCoord ).rgb;
	clip(col - 0.25f);
    return float4(col*gSunColor.rgb, 1.0f);
}

technique10 Clouds
{
    pass P0
    {
        SetVertexShader( CompileShader( vs_4_0, VertexShaderFunction() ) );
        SetGeometryShader( NULL );
        SetPixelShader( CompileShader( ps_4_0, PixelShaderFunction() ) );
		SetRasterizerState(NoCull);
		//SetBlendState(alphablend, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xffffffff);
  }
}
